package com.ruoyi.order.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.order.domain.SetMealDishRelation;
import com.ruoyi.order.service.ISetMealDishRelationService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 套餐菜品关系Controller
 * 
 * @author ruoyi
 * @date 2022-08-19
 */
@RestController
@RequestMapping("/order/relation")
public class SetMealDishRelationController extends BaseController
{
    @Autowired
    private ISetMealDishRelationService setMealDishRelationService;

    /**
     * 查询套餐菜品关系列表
     */
    @PreAuthorize("@ss.hasPermi('order:relation:list')")
    @GetMapping("/list")
    public TableDataInfo list(SetMealDishRelation setMealDishRelation)
    {
        startPage();
        List<SetMealDishRelation> list = setMealDishRelationService.selectSetMealDishRelationList(setMealDishRelation);
        return getDataTable(list);
    }

    /**
     * 导出套餐菜品关系列表
     */
    @PreAuthorize("@ss.hasPermi('order:relation:export')")
    @Log(title = "套餐菜品关系", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SetMealDishRelation setMealDishRelation)
    {
        List<SetMealDishRelation> list = setMealDishRelationService.selectSetMealDishRelationList(setMealDishRelation);
        ExcelUtil<SetMealDishRelation> util = new ExcelUtil<SetMealDishRelation>(SetMealDishRelation.class);
        util.exportExcel(response, list, "套餐菜品关系数据");
    }

    /**
     * 获取套餐菜品关系详细信息
     */
    @PreAuthorize("@ss.hasPermi('order:relation:query')")
    @GetMapping(value = "/{setMealDishRelationId}")
    public AjaxResult getInfo(@PathVariable("setMealDishRelationId") Long setMealDishRelationId)
    {
        return AjaxResult.success(setMealDishRelationService.selectSetMealDishRelationBySetMealDishRelationId(setMealDishRelationId));
    }

    /**
     * 新增套餐菜品关系
     */
    @PreAuthorize("@ss.hasPermi('order:relation:add')")
    @Log(title = "套餐菜品关系", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SetMealDishRelation setMealDishRelation)
    {
        return toAjax(setMealDishRelationService.insertSetMealDishRelation(setMealDishRelation));
    }

    /**
     * 修改套餐菜品关系
     */
    @PreAuthorize("@ss.hasPermi('order:relation:edit')")
    @Log(title = "套餐菜品关系", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SetMealDishRelation setMealDishRelation)
    {
        return toAjax(setMealDishRelationService.updateSetMealDishRelation(setMealDishRelation));
    }

    /**
     * 删除套餐菜品关系
     */
    @PreAuthorize("@ss.hasPermi('order:relation:remove')")
    @Log(title = "套餐菜品关系", businessType = BusinessType.DELETE)
	@DeleteMapping("/{setMealDishRelationIds}")
    public AjaxResult remove(@PathVariable Long[] setMealDishRelationIds)
    {
        return toAjax(setMealDishRelationService.deleteSetMealDishRelationBySetMealDishRelationIds(setMealDishRelationIds));
    }
}
